package com.huluobo.lib_http

import com.tencent.mmkv.MMKV
import com.zyj.retrofit.adapter.FlowCallAdapterFactory
import okhttp3.OkHttpClient
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

/**
 *  Created by LC on 2025/7/22.
 *  携带token的Retrofit
 */
class TokenRetrofitImpl : BaseRetrofitImpl() {
    override fun createRetrofit(): Retrofit {
        return Retrofit.Builder()
            .baseUrl(Const.BASE_URL)
            .client(
                createHttp()
                    .addInterceptor { chain ->
                        chain.proceed(
                            chain.request().newBuilder().addHeader(
                                Const.PARAM_TOKEN,
                                MMKV.defaultMMKV().decodeString(Const.PARAM_TOKEN).toString()
                            ).build()
                        )
                    }.build()
            )
            .addConverterFactory(GsonConverterFactory.create())
            .addCallAdapterFactory(FlowCallAdapterFactory.create())
            .build()

    }
}